/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-06-15
 * Time: 21:14
 */
//力扣：https://leetcode.cn/problems/missing-number-lcci/description/
//数组nums包含从0到n的所有整数，但其中缺了一个。请编写代码找出那个缺失的整数。你有办法在O(n)时间内完成吗？
public class Test {
        public static int missingNumber(int[] nums) {
            int n=nums.length*(nums.length+1)/2;
            for(int i=0;i<nums.length;i++)
                n=n-nums[i];
            return n;
        }

    public static void main(String[] args) {
        int[] arr={9,6,4,2,3,5,7,0,1};
        System.out.println(missingNumber(arr));
    }
}
